<template>
  <div class="mapping-page">
    <!-- 头部盒子 -->
    <div class="header">
      <!-- 页面标题 -->
      <div class="title">
        <h4>系统管理</h4>
      </div>
      <div class="right">
        <!-- 搜索表单 -->
        <el-form size="small" :inline="true" style="display: inline-block">
          <el-form-item>
            <el-input placeholder="系统名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input placeholder="AppName"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary">查询</el-button>
          </el-form-item>
        </el-form>
        <!-- 新增按钮 -->
        <el-button
          size="small"
          style="height: 32px"
          type="primary"
          plain
          @click="add"
          >新增</el-button
        >
      </div>
    </div>

    <!-- table表格 -->
    <div class="table">
      <el-table :data="list" border style="width: 100%" height="500">
        <el-table-column prop="date" label="系统名称"></el-table-column>
        <el-table-column prop="name" label="AppName"></el-table-column>
        <el-table-column prop="address" label="页面列表">
          <template>
            <el-link type="primary" :underline="false" @click="viewPage"
              >点击查看</el-link
            >
          </template>
        </el-table-column>
        <el-table-column prop="address" label="备注"></el-table-column>
        <el-table-column prop="address" label="操作" width="150">
          <template>
            <el-button size="mini" @click="edit">编辑</el-button>
            <el-button size="mini" type="danger">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 新增和编辑的对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="showDialog"
      width="35%"
      :before-close="handleCloseDialog"
    >
      <el-form label-width="80px" style="width: 80%">
        <el-form-item label="系统名称">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="AppName">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 页面列表抽屉 -->
    <el-drawer
      title="页面列表"
      :visible.sync="showDrawer"
      :before-close="handleCloseDrawer"
      :modal="false"
      :modal-append-to-body="false"
    >
      <el-tree
        :data="data"
        node-key="id"
        default-expand-all
        :props="defaultProps"
      ></el-tree>
    </el-drawer>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          date: "系统1",
          name: "App1",
          address: "",
        },
        {
          date: "系统2",
          name: "App2",
          address: "",
        },
        {
          date: "系统3",
          name: "App3",
          address: "",
        },
        {
          date: "系统4",
          name: "App4",
          address: "",
        },
      ],
      data: [
        {
          id: 1,
          label: "一级 1",
          children: [
            {
              id: 4,
              label: "二级 1-1",
              children: [
                {
                  id: 9,
                  label: "三级 1-1-1",
                },
              ],
            },
          ],
        },
        {
          id: 2,
          label: "一级 2",
          children: [
            {
              id: 6,
              label: "二级 2-2",
              children: [
                {
                  id: 9,
                  label: "三级 2-1-1",
                },
              ],
            },
          ],
        },
        {
          id: 3,
          label: "一级 3",
          children: [
            {
              id: 7,
              label: "二级 3-1",
              children: [
                {
                  id: 9,
                  label: "三级 3-1-1",
                },
              ],
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      title: "新增",
      showDialog: false,
      showDrawer: false,
    };
  },

  methods: {
    // 封装一个处理弹窗关闭的方法：需要关闭的时候调用，清楚表单的数据，初始化表单
    handleCloseDialog() {
      this.showDialog = false;
    },
    cancel() {
      this.showDialog = false;
    },
    edit() {
      this.title = "编辑";
      this.showDialog = true;
    },
    add() {
      this.title = "新增";
      this.showDialog = true;
    },
    viewPage() {
      this.showDrawer = true;
    },
    handleCloseDrawer() {
      this.showDrawer = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.mapping-page {
  background-color: #fff;
  padding: 0 50px 50px 50px;

  .header {
    display: flex;
    text-align: center;
    justify-content: space-between;
    align-items: center;
    // padding: 0 50px;

    .title {
      font-size: 20px;
    }

    .right {
      display: flex;
      text-align: center;
      padding-top: 30px;
    }
  }

  .table {
  }

  .dialogBox {
    margin: 0 auto;
  }

  .drawerBox {
    // padding: 20px 40px;

    .rule {
    }
  }
}
</style>


